﻿@model IEnumerable<Shop.Models.ProductInfo>

@{
    ViewBag.Title = "设置规格";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutList.cshtml";
}

<h2>@ViewBag.Product.Name</h2>

<p>
    <button id="btnAdd">添加</button>
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>

        <th>
            @Html.DisplayNameFor(model => model.ROM)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Storage)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.CPU)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.ROM)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Storage)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.CPU)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>
            <td>
                @Html.ActionLink("修改", "Edit", new { id = item.Id }) |
                @Html.ActionLink("删除", "Delete", new { id = item.Id }) |
                <a href="#"  onclick="openColor(@item.Id)">设置颜色</a>
               
            </td>
        </tr>
    }

</table>

@*添加修改窗口*@
<div class="modal fade" id="infoModal" tabindex="-1" role="dialog">
    <div class="modal-dialog  modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加</h4>
            </div>
            <div class="modal-body" style="height:500px">
                <iframe frameborder="0" src="" name="editForm" style="width:100%;height:100%"></iframe>
            </div>

        </div>
    </div>
</div>

@section scripts{
    <script>
        function remove(id) {
                if (confirm('确定要删除吗？')) {
                    $.ajax({
                        url: '@Url.Action("delete")' + "/" + id,
                        success: function (res) {
                            alert(res.msg);
                            if (res.success) {
                                $("#productTable").bootstrapTable('refresh');
                            }
                        }
                    })
                }
        }
        // 修改
        function edit(id) {
             $('iframe').attr('src', '@Url.Action("Edit")/'+id);
                $('.modal-title').html("修改")
                $('#productModal').modal('show')
        }
        // 关闭弹出窗口并刷新数据
        window.closeModal = function () {
            $('#infoModal').modal('hide')
            // 刷新页面
            location.reload();
        }

        // 设置颜色按钮
        function openColor(id) {
             $('iframe').attr('src', '@Url.Action("SetColor")/'+id);
             $('.modal-title').html("设置颜色")
            $('#infoModal').modal('show')
            return false;
        }


        $(function () {
             // 添加
            $('#btnAdd').click(function () {
                $('iframe').attr('src', '@Url.Action("createInfo",new {productId= ViewBag.Product.Id })');
                $('.modal-title').html("添加")
                $('#infoModal').modal('show')
            })


        })
    </script>
    
    
    }